package junior.Simulation模拟;

public class SingleObject {
    //创建 SingleObject 的一个对象
    private static SingleObject instance = new SingleObject();

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    int num = 1;
    //让构造函数为 private，这样该类就不会被实例化
    private SingleObject(){}

    //获取唯一可用的对象
    public static SingleObject getInstance(){
        return instance;
    }

    public void showMessage(){
        System.out.println("Hello World!");
        System.out.println("this.num:"+this.num);
    }
    public void setNumAddOne(){
        this.num += 1;
    }
}
